package com.ct.code.tools.util;

public class StringUtil {

	
	public static boolean isEmpty(String string)
	{
		if(null == string || "".equals(string.trim())) return true;
		return false;
	}
	
	public static String firstCap(String string)
	{
		if(isEmpty(string)) return "";
		
		return string.substring(0, 1).toUpperCase() + string.substring(1);
	}
	
	public static String firstLower(String string)
	{
		if(isEmpty(string)) return "";
		return string.substring(0, 1).toLowerCase() + string.substring(1);
	}
	
	
	public static String tableName2JavaName(String string,boolean isFirstCap)
	{
		if(isEmpty(string)) return "";
		int index = string.indexOf("_");
		
		String result = string.toUpperCase().substring(index);
		
		String[] results = result.split("_");
		StringBuffer sb = new StringBuffer();
		for (String res : results) {
			if(!isEmpty(res))
			{
				String lowerCaseRes = res.toLowerCase();
				sb.append(firstCap(lowerCaseRes));
			}
		}
		return isFirstCap ? sb.toString() : firstLower(sb.toString()); 
	}
	
	public static String fieldName2JavaName(String string,boolean isFirstCap)
	{
		if(isEmpty(string)) return "";
		
		String result = string.toUpperCase();
		
		String[] results = result.split("_");
		StringBuffer sb = new StringBuffer();
		for (String res : results) {
			if(!isEmpty(res))
			{
				String lowerCaseRes = res.toLowerCase();
				sb.append(firstCap(lowerCaseRes));
			}
		}
		return isFirstCap ? sb.toString() : firstLower(sb.toString()); 
	}
	
	
	
	public static void main(String[] args) {
		System.out.println(tableName2JavaName("td_bind_Id",true));
		System.out.println(fieldName2JavaName("td_bind_Id",false));
//		System.out.println(dbName2JavaName("t_code_note",false));
//		System.out.println(dbName2JavaName("is_public",true));
//		System.out.println(dbName2JavaName("is_public",false));
	}
	
}
